﻿//创建时间: 2010-10-11
//创建作者: 李晓忠
//功能说明: CMS系统 结点分组
//最后修改: 2010-10-11
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;

namespace TRPOP.CMS.Web.Admin
{
    public partial class NodeGroup_save : BaseAdmin
    {
        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.Node_Save;
        }
        #endregion

        #region 页面变量
        protected bool m_IsAdd = true;
        protected int m_id = 0;
        NodeGroupManage oNodeGroupManage = new NodeGroupManage();
        protected string m_linkStr = "";
        #endregion

        #region 页面事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
            }
            LoadData();
        }
        /// <summary>
        /// 添加或修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strMSG = "分组名";
            if (!PageAssist.CheckForm(txtName, ref strMSG) )
            {
                Alert(strMSG);
                return;
            }
            NodeGroupInfo oNodeGroupInfo = new NodeGroupInfo();
            int.TryParse(GetRequestViewState("id"), out m_id);
            if (m_id > 0)
            {
                if (GetPageViewState("model") != null)
                {
                    oNodeGroupInfo = (NodeGroupInfo)GetPageViewState("model");
                }
                else
                {
                    oNodeGroupInfo = oNodeGroupManage.GetInfoById(m_id);

                    if (oNodeGroupInfo == null)
                    {
                        oNodeGroupInfo = new NodeGroupInfo();
                        Alert("要修改的信息不存在了"); ExecuteJs("parent.reset();"); return;
                    }
                }
            }
                                 
            oNodeGroupInfo.Name = txtName.Text.Trim();          
            oNodeGroupInfo.Nodeids = txtNodeids.Text.Trim();
            SubmitAlertAndParReset(oNodeGroupManage.Save(oNodeGroupInfo));
        }
        #endregion

        #region 页面方法

        public void LoadBase()
        {
            int.TryParse(InitRequestViewState("id"), out m_id);
            //初始化textbox等的数据
            NodeGroupInfo oNodeGroupInfo = oNodeGroupManage.GetInfoById(m_id);
            
            if (oNodeGroupInfo != null)
            {               
                txtName.Text = oNodeGroupInfo.Name;
                txtNodeids.Text = oNodeGroupInfo.Nodeids;

                InitPageViewState("model", oNodeGroupInfo);
                m_IsAdd = false;
            }
            else
            {
                m_IsAdd = true;
            }
        }
        /// <summary>
        /// 加载所有参数类型的的链接页面
        /// </summary>
        public void LoadData()
        {
            //初始化快捷链接
            //foreach (NodeGroupInfo TempInfo in oNodeGroupManage.GetListByCondition(0, "", "ParamTypeId"))
            //{
            //    m_linkStr += " | " + "<a href=\"ParamType_Save.aspx?id=" + TempInfo.ParamTypeId.ToString() + "\" >" + TempInfo.Name + "</a>";
            //}
        }
        #endregion
    }
}
